<?php
include '../classes/export.class.php';


if( isset($_POST['submit']) ){
	include "template.php";
	$export = new Export($db);
	
	$year = null;
	$month = null;
	$project = null;
	
	if( isset($_POST['year']) )
		$year = $_POST['year'];
	
	if( isset($_POST['month']) )
		$month = $_POST['month'];
	
	if( isset($_POST['projects']) )
		$project = $_POST['projects'];
	
	switch($_POST['download']){
		case "csv":
			$export->exportCSV($year, $month, $project);
			break;
		case "xml":
			$export->exportXML($year, $month, $project);
			break;
		case "ical":
			$export->exportICal($project);
			break;
	}
	
}
else{
	
$projects_resource = $db->query("SELECT name, pk_nr FROM Projekt");

?>
<div>
<form action="export.php" method="post">
<label>Filter: </label><br />
<input type="text" name="year"> Year<br />
<input type="text" name="month"> Month<br />
<select name="projects" size="1">
<option value="">Alle</option>
<?php 
foreach($projects_resource as $project){
	echo "<option value=\"" . $project['pk_nr'] . "\">" . $project['name'] . "</option>";
}
?>
</select>
<label>Export as: </label><br />
<input type="radio" name="download" value="csv"> CSV<br />
<input type="radio" name="download" value="xml"> XML<br />
<input type="radio" name="download" value="ical"> iCal<br />
<input type="submit" name="submit" value="Export">
</form>
</div>
<?php } ?>